<!DOCTYPE html>
<html>
<head>
	<title>Dropdowns</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<script src="js/libs/modernizr-2.6.1.min.js"></script>
	<style>
	    body, nav, ul, li, a  {margin: 0; padding: 0;}
		body {font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; }
		a {text-decoration: none;}
		* {
		  -moz-box-sizing: border-box;
		  -webkit-box-sizing: border-box;
		  box-sizing: border-box;
		}
		#container, .txt {
		    margin: 10px auto;

		}
		.toggleMenu {
		    display:  none;
		    background: #666;
		    padding: 10px 15px;
		    color: #fff;
		}
		.nav {
		    list-style: none;
		     *zoom: 1;
		     background:#175e4c;
		}
		.nav:before,
		.nav:after {
		    content: " ";
		    display: table;
		}
		.nav:after {
		    clear: both;
		}
		.nav ul {
		    list-style: none;
		    width: 100%;
		}
		.nav a {
		    padding: 10px 15px;
		    color:#fff;
		    text-align: center;
		}
		.nav li {
		    position: relative;
		}
		.nav > li {
		    float: left;
		    width: 16.66%;
		    border-left: 1px solid yellow;
		    border-right: 1px solid yellow;
		}
		.nav > li > .parent {
		    background-image: url("img/web/arrow_down.png");
		    background-repeat: no-repeat;
		    background-position: 80%;
		}
		.nav > li > a {
		    display: block;
		}
		.nav li  ul {
		    position: absolute;
		    left: -9999px;
		}
		.nav > li.hover > ul {
		    left: 0;
		}
		.nav li li.hover ul {
		    left: 100%;
		    top: 0;
		}
		.nav li li a {
		    display: block;
		    background: #1d7a62;
		    position: relative;
		    z-index:100;
		    border-top: 1px solid #175e4c;
		}
		.nav li li li a {
		    background:#249578;
		    z-index:200;
		    border-top: 1px solid #1d7a62;
		}
		.default {
		    width: 90%;
		    box-shadow: 0 5px 20px #888;
		    -webkit-box-shadow: 0 5px 20px #888;
		    -moz-box-shadow: 0 5px 20px #888;
		}

		.fixed {
		    position: fixed;
		    top: -11px;
		    left: 0;
		    width: 100%;
		    box-shadow: 0 0 40px #222;
		    -webkit-box-shadow: 0 0 40px #222;
		    -moz-box-shadow: 0 0 40px #222;
		}

		@media screen and (max-width: 768px) {
		    .active {
		        display: block;
		    }
		    .nav > li {
		        float: none;
		    }
		    .nav > li > .parent {
		        background-position: 95% 50%;
		    }
		    .nav li li .parent {
		        background-image: url("img/web/arrow_down.png");
		        background-repeat: no-repeat;
		        background-position: 95% 50%;
		    }
		    .nav ul {
		        display: block;
		        width: 100%;
		    }
		   .nav > li.hover > ul , .nav li li.hover ul {
		        position: static;
		    }

		}
    </style>
</head>
<body>

<nav id="container" class="default">

<a class="toggleMenu" href="#">Menu</a>

<ul class="nav">
	<li>
		<a href="#">Inicio</a>
	</li>
	<li>
		<a href="#">Franquicias</a>
		<ul>
			<li>
				<a href="#">Comercio</a>
				<ul>
					<li><a href="#">Denim</a></li>
					<li><a href="#">Knits</a></li>
				</ul>
			</li>
			<li>
				<a href="#">Hosteleria</a>
				<ul>
					<li><a href="#">Denim</a></li>
					<li><a href="#">Knits</a></li>
				</ul>
			</li>
			<li>
				<a href="#">Moda</a>
				<ul>
					<li><a href="#">Denim</a></li>
					<li><a href="#">Knits</a></li>
				</ul>
			</li>
			<li>
				<a href="#">Servicios</a>
				<ul>
					<li><a href="#">Denim</a></li>
					<li><a href="#">Knits</a></li>
				</ul>
			</li>
		</ul>
	</li>
	<li>
		<a href="#">Dresses</a>
		<ul>
			<li>
				<a href="#">Casual</a>
			</li>
			<li>
				<a href="#">Formal</a>
				<ul>
					<li><a href="#">Wedding</a></li>
					<li><a href="#">Party</a></li>
				</ul>
			</li>

		</ul>
	</li>
	<li>
		<a href="#">Sweaters</a>
		<ul>
			<li>
				<a href="#">Mens</a>
				<ul>
					<li><a href="#">Wool</a></li>
					<li><a href="#">Knitwear</a></li>
					<li><a href="#">Light Sweaters</a></li>
					<li><a href="#">Cardigans</a></li>
					<li><a href="#">Hoodies</a></li>
				</ul>
			</li>
			<li>
				<a href="#">Womens</a>
				<ul>
					<li><a href="#">Wool</a></li>
					<li><a href="#">Knitwear</a></li>
					<li><a href="#">Light Sweaters</a></li>
					<li><a href="#">Cardigans</a></li>
					<li><a href="#">Hoodies</a></li>
				</ul>
			</li>
		</ul>
	</li>
	<li>
		<a href="#">Outerwear</a>
		<ul>
			<li>
				<a href="#">Womens</a>
				<ul>
					<li><a href="#">Winter</a></li>
					<li><a href="#">Spring/Fall</a></li>
				</ul>
			</li>
			<li>
				<a href="#">Mens</a>
				<ul>
					<li><a href="#">Winter</a></li>
					<li><a href="#">Spring/Fall</a></li>
				</ul>
			</li>
		</ul>
	</li>
	<li>
		<a href="#">Franquicias</a>
	</li>
</ul>
</nav>

<div class="txt">
	<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
	tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
	quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
	consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
	cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
	proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
	<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
	tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
	quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
	consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
	cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
	proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
	<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
	tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
	quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
	consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
	cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
	proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
	<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
	tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
	quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
	consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
	cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
	proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
	<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
	tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
	quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
	consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
	cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
	proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
	<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
	tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
	quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
	consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
	cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
	proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>

	var menu = $('#container'),
    pos = menu.offset();

    $(window).scroll(function(){
      if($(this).scrollTop() > pos.top+menu.height() && menu.hasClass('default')){
        menu.fadeOut('fast', function(){
          $(this).removeClass('default').addClass('fixed').fadeIn('fast');
        });
      } else if($(this).scrollTop() <= pos.top && menu.hasClass('fixed')){
        menu.fadeOut('fast', function(){
          $(this).removeClass('fixed').addClass('default').fadeIn('fast');
        });
      }
    });

var ww = document.body.clientWidth;

$(document).ready(function() {
	$(".nav li a").each(function() {
		if ($(this).next().length > 0) {
			$(this).addClass("parent");
		};
	})

	$(".toggleMenu").click(function(e) {
		e.preventDefault();
		$(this).toggleClass("active");
		$(".nav").toggle();
	});
	adjustMenu();
})

$(window).bind('resize orientationchange', function() {
	ww = document.body.clientWidth;
	adjustMenu();
});

var adjustMenu = function() {
	if (ww < 768) {
		$(".toggleMenu").css("display", "inline-block");
		if (!$(".toggleMenu").hasClass("active")) {
			$(".nav").hide();
		} else {
			$(".nav").show();
		}
		$(".nav li").unbind('mouseenter mouseleave');
		$(".nav li a.parent").unbind('click').bind('click', function(e) {
			// must be attached to anchor element to prevent bubbling
			e.preventDefault();
			$(this).parent("li").toggleClass("hover");
		});
	}
	else if (ww >= 768) {
		$(".toggleMenu").css("display", "none");
		$(".nav").show();
		$(".nav li").removeClass("hover");
		$(".nav li a").unbind('click');
		$(".nav li").unbind('mouseenter mouseleave').bind('mouseenter mouseleave', function() {
		 	// must be attached to li so that mouseleave is not triggered when hover over submenu
		 	$(this).toggleClass('hover');
		});
	}
}
</script>
</body>
</html>